﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using VirtualPress.Tool.Framework;

namespace VirtualPress.Infrastructure.Entities.Repository
{
    [Table("Invite")]
    public class Invite : IEntity<Invite>
    {
        [Key]
        [DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        public int journalId { get; set; }

        [Column(TypeName="nvarchar")]
        [StringLength(64)]
        public string SendFrom { get; set; }
        
        [Column(TypeName = "nvarchar")]
        [StringLength(64)]
        public string SendTo { get; set; }

        /// <summary>
        /// 0:邀请
        /// 1:同意
        /// 2:拒绝
        /// </summary>
        public int Status { get; set; }

        [Column(TypeName="nvarchar")]
        [StringLength(256)]
        public string Message { get; set; }

        public DateTime CreateTime { get; set; }

        public override Invite Find(string key)
        {
            int id = key.ToInt32();
            return Find(c => c.Id == id);
        }

        public override Invite Find(System.Linq.Expressions.Expression<Func<Invite, bool>> where)
        {
            using (Context ctx = new Context())
            {
                return ctx.Invite.FirstOrDefault(where);
            }
        }

        public override bool Any(System.Linq.Expressions.Expression<Func<Invite, bool>> where)
        {
            using (Context ctx = new Context())
            {
                return ctx.Invite.Any(where);
            }
        }
    }
}
